{extend name="/base"}

{block name="header"}
    <h2>分配角色</h2>
{/block}

{block name="body"}
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="" class="layui-form-label">用户名</label>
            <div class="layui-form-mid layui-word-aux">{$user->username}</div>
        </div>
        <div class="layui-form-item">
            <label for="" class="layui-form-label">昵称</label>
            <div class="layui-form-mid layui-word-aux">{$user->nickname}</div>
        </div>
        <div class="layui-form-item">
            <label for="" class="layui-form-label">角色</label>
            <div class="layui-input-block" style="width: 700px">
                {foreach $roles as $role}
                <input type="checkbox" name="roles[]" value="{$role['id']}" title="{$role['name']}" {if isset($role['own']) && $role['own'] } checked {/if} >
                {/foreach}
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="formDemo">确 认</button>
                <a  class="layui-btn layui-btn-sm" href="{:url('index')}" >返 回</a>
            </div>
        </div>
    </form>
{/block}

{block name="js"}
<script>
    layui.use(['jquery','table','element','form','layer'],function () {
        var table=layui.table;
        var $=layui.jquery;
        var element=layui.element;
        var form=layui.form;
        var layer=layui.layer;

        form.on('submit(formDemo)',function (data) {
            var load = layer.load();
            $.post("{:url('role',['id'=>$user->id])}",data.field,function (res) {
                layer.close(load);
                if (res.code==1){
                    layer.msg(res.msg,{icon:1,time:1500},function () {
                        if (res.url) location.href = res.url;
                    })
                } else {
                    layer.msg(res.msg,{icon:2,time:1500})
                }
            });
            return false
        })

    })
</script>
{/block}